class ListNode {
  constructor(val, next) {
    this.val = (val === undefined ? 0 : val);
    this.next = (next === undefined ? null : next);
  }
}
var mergeKLists = function(lists) {
  let curr = new ListNode();
  let dumm = curr;
  let arr = [];
  for(let list of lists){
      while(list){
          arr.push(list.val);
          list = list.next;
      }
  }
  arr = arr.sort((a,b) => a-b);
  for(let i = 0 ; i<arr.length;i++){
      curr.next = new ListNode(arr[i]);
      curr = curr.next;
  }
  return dumm.next;
};

console.log(mergeKLists([1,4,5],[1,3,4],[2,6]));